home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.08 Aug 90 / Test Object Source / CWavePanel.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-06  |  4.2 KB  |  166 lines  |  [TEXT/KAHL]

  1. /*************************************************
  2.  CWavePanel.c
  3.  
  4.  Part of the WavePanel class, to show how to use
  5.  the DigitalControl class.
  6.  
  7.  SUPERCLASS = CPicture
  8.  
  9.  © 1989 Enrico Colombini. All rights reserved.
  10. *************************************************/
  11. #include "CWavePanel.h"
  12. #include <stdio.h>
  13.  
  14.         /*rsrc ID for DigitalControl object:*/
  15. #define digitalControlResID    600
  16.  
  17.         /*command numbers for display update*/
  18. #define DISPLAY_AMPA_CMD            2000L
  19. #define DISPLAY_FREQA_CMD        2001L
  20. #define DISPLAY_AMPB_CMD            2002L
  21. #define DISPLAY_FREQB_CMD        2003L
  22. #define DISPLAY_PHASEB_CMD        2004L
  23.  
  24.         /*DigitalControls positions*/
  25. #define CTR_HPOS                    38
  26. #define CTR_AMPA_VPOS        31
  27. #define CTR_FREQA_VPOS        56
  28. #define CTR_AMPB_VPOS        154
  29. #define CTR_FREQB_VPOS        179
  30. #define CTR_PHASEB_VPOS    204
  31.  
  32.         /*frequency limits and display steps*/
  33. #define MIN_FREQ                    50
  34. #define MAX_FREQ                    1800
  35. #define FREQ_STEP                    40
  36. #define FREQ_THRESHOLD        40
  37.  
  38.         /*non-zero starting values*/
  39. #define START_AMPA                100
  40. #define START_FREQA            600
  41. #define START_FREQB            600
  42.  
  43. /*************************************************
  44.  IWavePanel
  45.  
  46.  Initialize a CWavePanel object. The intialization
  47.  is typical of an object descending from the
  48.  CPicture class. However, there is no rType
  49.  parameter, and 'PctP' is used instead.
  50. *************************************************/
  51. void CWavePanel::IWavePanel(
  52.     short        resID,
  53.     CView        *anEnclosure,
  54.     CBureaucrat    *aSupervisor)
  55. {
  56.         /*first, init itself*/
  57.     inherited::IViewRes(
  58.         'PctP',resID,anEnclosure,aSupervisor);
  59.     
  60.         /*create a DigitalControl for Amplitude A*/
  61.     ctrAmpA = new(CDigitalControl);
  62.     ctrAmpA->IDigitalControl(
  63.         digitalControlResID,this,this);
  64.     ctrAmpA->Place(CTR_HPOS,CTR_AMPA_VPOS,FALSE);
  65.     ctrAmpA->SetDisplayCmd(DISPLAY_AMPA_CMD);
  66.     ctrAmpA->SetValue(START_AMPA);
  67.  
  68.         /*create a DigitalControl for Frequency A*/
  69.     ctrFreqA = new(CDigitalControl);
  70.     ctrFreqA->IDigitalControl(
  71.         digitalControlResID,this,this);
  72.     ctrFreqA->Place(CTR_HPOS,CTR_FREQA_VPOS,FALSE);
  73.     ctrFreqA->SetDisplayCmd(DISPLAY_FREQA_CMD);
  74.     ctrFreqA->SetMinValue(MIN_FREQ);
  75.     ctrFreqA->SetMaxValue(MAX_FREQ);
  76.     ctrFreqA->SetSteps(1,FREQ_STEP,FREQ_THRESHOLD);
  77.     ctrFreqA->SetValue(START_FREQA);
  78.     
  79.         /*create a DigitalControl for Amplitude B*/
  80.     ctrAmpB = new(CDigitalControl);
  81.     ctrAmpB->IDigitalControl(
  82.         digitalControlResID,this,this);
  83.     ctrAmpB->Place(CTR_HPOS,CTR_AMPB_VPOS,FALSE);
  84.     ctrAmpB->SetDisplayCmd(DISPLAY_AMPB_CMD);
  85.  
  86.         /*create a DigitalControl for Frequency B*/
  87.     ctrFreqB = new(CDigitalControl);
  88.     ctrFreqB->IDigitalControl(
  89.         digitalControlResID,this,this);
  90.     ctrFreqB->Place(CTR_HPOS,CTR_FREQB_VPOS,FALSE);
  91.     ctrFreqB->SetDisplayCmd(DISPLAY_FREQB_CMD);
  92.     ctrFreqB->SetMinValue(MIN_FREQ);
  93.     ctrFreqB->SetMaxValue(MAX_FREQ);
  94.     ctrFreqB->SetSteps(1,FREQ_STEP,FREQ_THRESHOLD);
  95.     ctrFreqB->SetValue(START_FREQB);
  96.  
  97.         /*create a DigitalControl for relative Phase*/
  98.     ctrPhaseB = new(CDigitalControl);
  99.     ctrPhaseB->IDigitalControl(
  100.         digitalControlResID,this,this);
  101.     ctrPhaseB->Place(
  102.         CTR_HPOS,CTR_PHASEB_VPOS,FALSE);
  103.     ctrPhaseB->SetDisplayCmd(DISPLAY_PHASEB_CMD);
  104.     ctrPhaseB->SetMinValue(-180);
  105.     ctrPhaseB->SetMaxValue(180);
  106. }
  107.  
  108. /*************************************************
  109.  DoCommand {OVERRIDE}
  110.  
  111.  Handle commands from enclosed DigitalControls
  112.  (display update), or pass command to supervisor
  113.  if not recognized.
  114. *************************************************/
  115. void CWavePanel::DoCommand(long theCommand)
  116. {
  117.     enum        type { AMPL, FREQ, PHASE };
  118.     CDigitalControl    *dctrl = NULL;
  119.     short    dispType;
  120.     short    val;
  121.     char      buf[6];
  122.     
  123.     switch(theCommand) {
  124.  
  125.     case DISPLAY_AMPA_CMD:
  126.         dctrl = ctrAmpA;
  127.         dispType = AMPL;
  128.         break;
  129.     case DISPLAY_FREQA_CMD:
  130.         dctrl = ctrFreqA;
  131.         dispType = FREQ;
  132.         break;
  133.     case DISPLAY_AMPB_CMD:
  134.         dctrl = ctrAmpB;
  135.         dispType = AMPL;
  136.         break;
  137.     case DISPLAY_FREQB_CMD:
  138.         dctrl = ctrFreqB;
  139.         dispType = FREQ;
  140.         break;
  141.     case DISPLAY_PHASEB_CMD:
  142.         dctrl = ctrPhaseB;
  143.         dispType = PHASE;
  144.         break;
  145.         
  146.     default:
  147.         inherited::DoCommand(theCommand); /*not mine*/
  148.         break;
  149.     }
  150.     
  151.     if (dctrl != NULL) {            /*display to refresh*/
  152.         val = dctrl->GetValue();
  153.         sprintf(buf,"%04d",val);    /*build text*/
  154.         if (dispType == AMPL) {    /*AMPL: fake point*/
  155.             buf[0] = buf[1];
  156.             buf[1] = '.';
  157.         } else if  (dispType == PHASE) { /*add sign*/
  158.             buf[0] = (val > 0) ? '+' :
  159.                 ((val < 0) ? '-' : ' ');
  160.         }
  161.         dctrl->SetDisplayText(buf);    /*set new text*/
  162.     }
  163. }
  164.  
  165.  
  166.